<?php


/**
 * Notes:
 * PROJECT_NAME : ERP v1.8 重构erp
 * User: 夏鱼儿<397072174@qq.com>
 * Date: 2024/4/12
 * Time: 15:45
 */

namespace app\admin\controller;

use app\admin\model\Company;
use app\company\model\Supplier;
use think\db\exception\DbException;
use think\Response;
use app\admin\model\GoodsRule;
use app\admin\model\CompanyOrder;

class Stat extends Base
{

    /**
     * 首页统计
     * @return Response
     * @throws DbException
     */
    public function list(): Response
    {

        //基础信息
        $base['company_count']              = Company::count();//公司数量(企业数量)
        $base['company_count_day']          = Company::whereDay("create_time")->count();//公司数量(企业数量)今天新增
        $base['supplier_count_one']         = Supplier::where('type', 1)->count();//第三方(个人)数量
        $base['supplier_count_one_day']     = Supplier::whereDay("create_time")->where('type', 1)->count();//第三方(个人)数量今天新增
        $base['supplier_count_two']         = Supplier::where('type', 2)->count();//第三方(货主)数量
        $base['supplier_count_two_day']     = Supplier::whereDay("create_time")->where('type', 2)->count();//第三方(货主)数量今天新增
        $base['supplier_count_third']       = Supplier::where('type', 3)->count();//第三方(经销商)数量
        $base['supplier_count_third_day']   = Supplier::whereDay("create_time")->where('type', 3)->count();//第三方(经销商)数量今天新增
        $base['supplier_count_for']         = Supplier::where('type', 4)->count();//第三方(厂商)数量
        $base['supplier_count_for_day']     = Supplier::whereDay("create_time")->where('type', 4)->count();//第三方(厂商)数量今天新增
        $base['goods_rules_count']          = GoodsRule::count();//sku 数量
        $base['goods_rules_count_day']      = GoodsRule::whereDay("create_time")->count();//sku 数量(今日)
        $base['company_order_count']        = CompanyOrder::count();//进货单数量
        $base['company_order_count_day']    = CompanyOrder::whereDay("create_time")->count();//进货单数量(今天)
        $base['company_order_un_count']     = 0;//进货单数量(退货)
        $base['company_order_un_count_day'] = 0;//进货单数量(退货)(今天)

        //待办事项
        $event['company_order_count_one'] = CompanyOrder::where('order_status',1)->count();//采购单(待审核)
        $event['company_order_count_two'] = CompanyOrder::whereIn('order_status',[2,3])->count();//采购单(待上架)
        $event['company_order_count_third'] = CompanyOrder::where('order_status',5)->count();//采购单(已完成)

        return $this->success('请求成功', compact('base', 'event'));
    }
}